const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class GetQiniuTokenHandler extends BaseHandler {

    get pattern() {
        return "/assets/request-token/:ext_name";
    }

    doGET(request, response){
        
        let extName = request.params.ext_name;
        if (!extName) {
            response.json({
                success: false,
                error: '请提供要上传文件的扩展名！'
            });
        } else {
            let data = this.Controller.requestQiniuUptoken(extName);

            response.json({
                success: true,
                data: data
            });
        }
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = GetQiniuTokenHandler;